package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Mobile   string `gorm:"type:char(11);not null;unique;" json:"mobile"`
	Password string `gorm:"type:char(32);not null;" json:"password"`
}
type RealName struct {
	gorm.Model
	UserId int64  `gorm:"type:int;not null;unique;" json:"userId"`
	Name   string `gorm:"type:varchar(30);not null;" json:"name"`
	IdCard string `gorm:"type:char(36);not null;unique;" json:"idCard"`
}

func (u *User) FindUserByMobile(mobile string) (*User, error) {
	err := DB.Where("mobile=?", mobile).Find(&u).Error
	if err != nil {
		return nil, err
	}
	return u, nil
}
func (r *RealName) CheckRealNameByUserIdAndIdCard(userId int, idCard string) (*RealName, error) {
	err := DB.Where("user_id=? or id_card=?", userId, idCard).Find(&r).Error
	if err != nil {
		return nil, err
	}
	return r, nil
}
func (r *RealName) FindRealNameByUserId(id int64) (*RealName, error) {
	err := DB.Where("user_id=?", id).Find(&r).Error
	if err != nil {
		return nil, err
	}
	return r, nil
}
func (r *RealName) CreateRealname() error {
	err := DB.Create(&r).Error
	if err != nil {
		return err
	}
	return nil
}
